package user

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"zhuandan/data_source"
	"zhuandan/models"
)

func Userpricecl(ctx *gin.Context) {
	var orders []models.Buyorder
	data_source.Db.Where("status = 2").Find(&orders)
	for _, v := range orders {
		var user models.User
		data_source.Db.Where("id = ?", v.Uid).First(&user)
		userpricenew := models.Userpricenew{
			Uid:     v.Uid,
			Addtime: v.Addtime,
			State:   1,
			Price:   v.Price,
			Title:   "充值余额",
			Dqprice: user.Price + v.Price,
		}
		data_source.Db.Create(&userpricenew)
	}

}
func Usercx(ctx *gin.Context) {
	request := ProcuresBody{}
	ctx.ShouldBind(&request)
	uid := request.Uid
	var user_info models.User
	data_source.Db.Where("id = ?", uid).First(&user_info)
	data := Appaccountuser(user_info.Unionid)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    400,
		"error":   1,
		"success": 400,
		"data":    data,
		"msg":     "ok",
	})
	return

}

// fmt.Println(data)
// return
func Userpriceclorder(ctx *gin.Context) {
	var orders []models.Procureorder
	data_source.Db.Where("status != 4").Find(&orders)

	for _, v := range orders {
		var user models.User
		data_source.Db.Where("id = ?", v.Uid).First(&user)
		userpricenew := models.Userpricenew{
			Uid:     v.Uid,
			Addtime: v.Addtime,
			State:   2,
			Price:   v.Price * float64(v.Num),
			Title:   "购买信息" + v.Title,
			Dqprice: user.Price - v.Price*float64(v.Num),
		}
		data_source.Db.Create(&userpricenew)
	}

}
